import React, { useState, useEffect } from 'react';
import 'antd/dist/antd.css'
import '../css/index.scss'
import { Table, Button, Select, Space, Modal,Form,Switch,Input,message } from 'antd';
import axios from '../../../../../http/index'


export default function Add(props) {
    console.log(props.seedatas);
    const [seedatas,setseedatas] = useState({
        couponName:props.seedatas.title,
        selects:String(props.seedatas.elpcenter_show),
        see:true,
        see2:true,
    })
    const layout = {
        labelCol: { span: 5 },
        wrapperCol: { span: 19 },
    };
     // 添加弹窗警告提示
     const validateMessages = {
        required: '这是必填项哦',
        types: {
            email: '${label} is not a valid email!',
            number: '${label} is not a valid number!',
        },
        number: {
            range: '${label}必须大于${min}小于${max}',
        },

    };
    const onFinish = (values) => {
        console.log(values);
    };
// 提交
const [form] = Form.useForm();
const submits = async () => {
    try {
      const values = await form.validateFields();
      axios({
        method: "GET",
        url: '/system/invitation/invitationmanagement/updateHelpCenter',
        params:{
            classification:values.selects,
            elpcenter_show:values.see === true ? '0' : '1',
            help_question_title:'',
            help_text:'',
            id:'',
            title:values.couponName,
        }
    })
        .then((res) => {
            props.edits()
            console.log(res);
            message.success('修改成功');
        })
        .catch((err) => {
            console.log(err);
            message.error('修改失败');
        })
    } catch (errorInfo) {
      console.log('Failed:', errorInfo);
    }
  };
  const gender = () => {

  }
  const see = () => {

  }
  const couponName = () => {

  }
    return (
        <div>
              <Form {...layout} name="nest-messages"
                    onFinish={onFinish}
                    validateMessages={validateMessages}
                    form={form}
                    initialValues={{
                        ...seedatas
                    }}
                >
                    <Form.Item name='couponName' label="标题" rules={[{ required: true }]} >
                        <Input onBlur={couponName} placeholder="请输入标题" />
                    </Form.Item>
                   
                    <Form.Item label="分类名称" name='selects' >
                        <Select placeholder="请选择分类名称" onChange={gender} getPopupContainer={triggerNode => triggerNode.parentNode}>
                            <Select.Option value="1">常见问题</Select.Option>
                            <Select.Option value="2">金融问题</Select.Option>
                            <Select.Option value="3">售后问题</Select.Option>
                        </Select>
                    </Form.Item>
                    <Form.Item name='see' label="显示设置" valuePropName="checked">
                        <Switch checkedChildren="是" unCheckedChildren="否" defaultChecked onChange={see} defaultChecked={seedatas.dynamic === 1 ?  false : true}/>
                    </Form.Item>
                    <Form.Item name='see2' label="是否可查看" valuePropName="checked">
                        <Switch checkedChildren="是" unCheckedChildren="否" defaultChecked onChange={see} defaultChecked={seedatas.see === 2 ?  false : true}/>
                    </Form.Item>
                    <Form.Item wrapperCol={{ ...layout.wrapperCol, offset: 8 }} >
                    <Button type="primary" htmlType="submit" onClick={submits}>
                        提交
                    </Button>
                </Form.Item>
                </Form>

        </div>
    )
}
